<template>
	<view class="detail">
		<view>
			<image class="banner" :src="article.img_url"></image>
			<view class="title">
				{{ article.title }}
			</view>
			<view class="text">
				<view class="user">
					<image :src="user_info.avatar_url"></image>
					<view class="u-tit">
						<view class="b">{{ user_info.name }}</view>
						<view class="u-tit-s">{{ article.time }}</view>
					</view>
				</view>
				<view class="content">
					<rich-text :nodes="article.content"></rich-text>
				</view>
				<view class="like" @click="like">
					<uni-icons :type="flag?'hand-up-filled':'hand-up'" size="25px" :color="flag?'#ff9500':''"></uni-icons>
					<view>{{ article.like }}</view>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	import reviewItem from '../../components/review-item/review-item.vue';
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				index: 0,
				flag: 0,
				article: [],
				user_info: [],
				reivew: []
			}
		},
		computed: mapState(['isLogin','userInfo']),
		components: {
			'review-item': reviewItem
		},
		onLoad(options) {
			if(options.id!=null){
				this.getArticle(options.id)
				this.user_info = JSON.parse(options.userInfo)
				console.log(this.user_info)
			}
			else{
				this.index = options.index
				this.article = JSON.parse(options.data)
				this.user_info = this.article.user_info
			}
		},
		methods: {
			getArticle(id) {
				uni.request({
					url: 'http://www.yingke.com/Index/getArticleInfo?id='+id,
					method: 'POST',
					success: (res) => {
						this.article = res.data.data
					}
				})
			},
			like() {
				if(this.isLogin){
					uni.showToast({
						title: '当前未登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '../login/login'
						})
					},1000)
				}
				else{
					if(this.flag){
						this.article.like--
					}
					else
						this.article.like++
					this.flag = !this.flag
				}
				
			},
			goWrite() {
				uni.navigateTo({
					url: '../write/write'
				})
			}
		}
	}
</script>

<style lang="scss">
	.detail{
		.banner{
			width: 100%;
		}
		.title{
			margin-left: 10px;
			line-height: 30px;
			font-size: 25px;
			font-weight: bold;
		}
		.text{
			margin: 10px 10px;
			background: #fcfcfc;
			border-radius: 10px;
			border: 1px solid #eaeaea;
			box-shadow: 5px 5px 10px #eaeaea;
			padding: 10px 10px;
			.user{
				margin-top: 15px;
				display: flex;
				image{
					width: 40px;
					height: 40px;
					border-radius: 50px;
					box-shadow: 5px 5px 10px #eaeaea;
				}
				.u-tit{
					margin-left: 10px;
					.u-tit-s{
						font-size: 13px;
						color: #C0C0C0;
					}
				}
			}
			.content{
				margin-top: 10px;
			}
			.like{
				display: flex;
			}
		}
		.line{
			height: 5px;
			background: #eaeaea;
		}
		.review{
			margin: 10px 10px;
			.r-top{
				display: flex;
				.write{
					position: absolute;
					right: 15px;
					display: inline-flex;
				}
			}
			
		}
		.bottom{
			height: 50px;
			margin-top: 20px;
			text-align: center;
		}
	}
</style>
